<?php
/**
 * @version $Id: update_ping.php 181 2008-03-11 21:46:28Z mikhail.miguel $
 * @author  Takeshi Kuriyama <kuri@keynext.co.jp>
 * @copyright Copyrighted(c) 2007 by Takeshi Kuriyama <kuri@keynext.co.jp>
 */

$mytrustdirname = basename( dirname( __FILE__ ) ) ;
$mytrustdirpath = dirname( __FILE__ ) ;

require $mytrustdirpath.'/lib/session.php';
include_once XOOPS_ROOT_PATH.'/include/common.php';

// GET THIS MODULE HANDLER
require_once $mytrustdirpath.'/include/prepend.inc.php';

// language files
$langmanpath = XOOPS_TRUST_PATH.'/libs/altsys/class/D3LanguageManager.class.php';
if( ! file_exists( $langmanpath ) ) die( 'install the latest altsys' );
require_once( $langmanpath );
$langman =& D3LanguageManager::getInstance();
$langman->read( 'main.php' , $mydirname , $mytrustdirname ) ;

require_once $mytrustdirpath.'/include/form/EntryEditForm.class.php';
// session_start
$form =& D3blogSession::get('entry_form');

if(empty($form->update_ping_)) {
    D3blogSession::unregister('entry_form');
    redirect_header('details.php?bid='.$form->bid_, 1, _MD_D3BLOG_MESSAGE_NOW_FINISHING);
}

$results = array();
                 
require_once $mytrustdirpath.'/lib/trackback/trackback.php';
$trackback = new TrackbackService();
$trackback->_data['url'] = $form->pingdata_['blog_topurl'];
$trackback->_data['blog_name'] = $form->pingdata_['blog_name'];
$res = $trackback->_getUpdatepingBody();
if($trackback->isError($res)) {
    $results[] = $res->getMessage(); 
}

foreach($form->updateping_urls_ as $svr) {
    if(!$parsed_url = d3blog_validateUrl($svr)) {
        $results[] = sprintf(_MD_D3BLOG_MESSAGE_UPDATEPING_FAILED, htmlspecialchars($svr, ENT_QUOTES));
    } else {           
        $response = $trackback->sendWeblogUpdateping($parsed_url, 15);
        if($trackback->isError($response)) {
            $results[] = sprintf(_MD_D3BLOG_MESSAGE_UPDATEPING_FAILED, htmlspecialchars($svr, ENT_QUOTES)). '<br />'.$response->getMessage();
        } else {
            $results[] = sprintf(_MD_D3BLOG_MESSAGE_UPDATEPING_SUCCESS, htmlspecialchars($svr, ENT_QUOTES));
        }
    }
}

$redirect_message = '';
foreach($results as $result) {
    $redirect_message .= $result."<br />";
}
D3blogSession::unregister('entry_form');
redirect_header('details.php?bid='.$form->bid_, 1, $redirect_message."<br />"._MD_D3BLOG_MESSAGE_NOW_FINISHING);
exit;

?>